﻿@using Novagoal.Website.Models.Views
@using Novagoal.Website.WebApp.Helpers
@using Novagoal.Utils

@model PartiesMainViewModel
@{
    ViewBag.Title = string.Format("Novagoal | {0}", Model.Party.Name);
    Layout = "~/Views/Shared/MasterLayout.cshtml";
}
@section PageContent {
    <script src="@Url.Content("~/Scripts/novagoal-parties.js")" type="text/javascript"></script>
    <div class="main-content ui-corner-top">
        <div class="ui-widget-header ui-corner-all">
            <div class="title">@Model.Party.Name</div>
        </div>
        @{Html.RenderPartial("SubmitResults"); }
        <div class="ui-widget-content ui-corner-bottom">
            <div style="text-align:center; margin-top:-15px; margin-bottom:-25px">
                @Html.CreateImage(Model.Party.Tournament.TrophyPath, new { height = "60px" })
            </div>
            @Html.Hidden("PartyId", Model.Party.Id)
            @Html.FavoriteTeamSelection(Model.FavoriteTeam, Model.Party,string.Format("javascript:OpenFavoriteTeamSelection({0})", Model.Party.Tournament.Id), "Tu equipo")
            <table>
                <tr>
                    <td class="border" style="vertical-align:top">
                    <div style="max-height:500px; overflow:auto">
                        <table class="main-table">
                            <tr>
                                <th class="ui-widget-header ui-corner-all">Posicion</th>
                                <th class="ui-widget-header ui-corner-all">Nombre</th>
                                <th class="ui-widget-header ui-corner-all">Equipo</th>
                                <th class="ui-widget-header ui-corner-all">Puntos</th>
                            </tr>
                        @{var pos = 1;}
                        @foreach (var entry in Model.Ranking.RankingEntries)
                        {
                            <tr>
                                <td class="center">@pos</td>
                                <td><span>@Html.GetAvatar(entry.Person.Id, new { style = "height:50px; width:50px; vertical-align:middle" }) @entry.Person.FullName</span></td>
                                <td>@Html.TeamSpan(entry.Team, 20)</td>
                                <td class="center">@entry.TotalPoints</td>
                            </tr>
                            pos++;
                        }
                        </table>
                    </div>
                    </td>
                    <td class="border" style="vertical-align:top; max-width:200px">
                        <div id='chatResult' class='ui-state-error ui-corner-all' style='padding:2px; display:none'></div>
                        <p class="ui-widget-header ui-corner-all">Mensajes</p>
                        <div id="MessageContent" style="padding:10px; padding-right:10px; max-height:400px; overflow:auto"></div>
                        <div style="text-align:center">
                            @Html.TextBox("ChatMessage", string.Empty, new { style = "width:90%", onkeyup = string.Format("PublishMessage(event, {0})", Model.Party.Id) })
                        </div>
                    </td>
                </tr>
            </table>
            @if(Model.FinishedGames != null && Model.FinishedGames.Count > 0){
            <fieldset>
                <legend>Historial de Juegos</legend>
                <div id="accordion">
                @foreach(var game in Model.FinishedGames)
                {
                    <h3 id="@game.Id">
                    <a style="text-align:center" href="@Url.Action("Results", "Games", new { gameId = game.Id })">
                        @Html.TeamSpan(game.TeamA) 
                        <span style="font-size:15px"> @game.ActualResult.TeamAScore - @game.ActualResult.TeamBScore </span>
                        @Html.TeamSpan(game.TeamB) <br />
                        @{
                            var predictedPlayer = game.ActualResult.Player == null ? "Ninguno" : game.ActualResult.Player.Name;
                        }
                        <span style="font-size:smaller">@predictedPlayer</span>
                    </a></h3>
                    <div>Loading...</div>
                }
                </div>
            </fieldset>
            }
            <span>Te gustaria crear tu propio grupo? Contacta a los administradores</span>
        </div>
    </div>
}
